package com.zjlp.seproject.service.impl;

import com.zjlp.seproject.mapper.CommentMapper;
import com.zjlp.seproject.pojo.Comment;
import com.zjlp.seproject.pojo.CommentDetails;
import com.zjlp.seproject.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.Date;
import java.util.List;
@Service
public class CommentServiceImpl implements CommentService {

    @Autowired
    private CommentMapper commentMapper;

    public List<Comment> selectAll(){
        return commentMapper.selectAll();
    }

    public int deleteByPrimaryKey(Integer id){
        return commentMapper.deleteByPrimaryKey(id);
    }

    public int insert(Comment record){
        return commentMapper.insert(record);
    }

    public Comment selectByPrimaryKey(Integer id){
        return commentMapper.selectByPrimaryKey(id);
    }

    public int updateByPrimaryKey(Comment record){
        return commentMapper.updateByPrimaryKey(record);
    }

    @Override
    public Integer addComment(Comment comment) {
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        comment.setTime(simpleDateFormat.format(date));
        return commentMapper.addComment(comment);
    }

    @Override
    public List<CommentDetails> getCommnet(Integer id) {
        List<CommentDetails> result = commentMapper.getComment(id);
        Collections.reverse(result);
        return result;
    }
}
